package cn.tinlan.shopcoin.app.mine.set;

import android.content.Intent;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;
import com.zhouyou.http.EasyHttp;
import com.zhouyou.http.callback.CallBackProxy;
import com.zhouyou.http.callback.SimpleCallBack;
import com.zhouyou.http.exception.ApiException;

import butterknife.BindView;
import cn.tinlan.shopcoin.R;
import cn.tinlan.shopcoin.Utils.SPUtils;
import cn.tinlan.shopcoin.app.koi.model.KoiSeekModel;
import cn.tinlan.shopcoin.base.BaseActivity;
import cn.tinlan.shopcoin.base.CustomApiResult;
import cn.tinlan.shopcoin.widget.category.Constants;

/**
 * Created by Mortimer on 2018/12/11. 16:53
 * 佛祖🙏，永无bug。
 */
public class MineWalletActivity extends BaseActivity implements View.OnClickListener{

    @BindView(R.id.mine_wallet_title)
    TitleBar walletTitleBar;
    @BindView(R.id.wallet_money)
    TextView walletMoneyTV;
    @BindView(R.id.wallet_recharge_btn)
    Button walletRechargeB;
    @BindView(R.id.wallet_withdraw_btn)
    Button walletWithdrawB;
    @BindView(R.id.wallet_recharge_record)
    View walletRechargeV;
    @BindView(R.id.wallet_withdraw_record)
    View walletWithdrawV;
    @BindView(R.id.wallet_change_record)
    View walletChangeV;

    public static final int REQUEST_CODE = 1653;
    public static final int REQUEST_CODE1 = 1654;

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_mine_wallet;
    }

    @Override
    public void initView() {
        super.initView();
        drawableDefaultBar();
        bindSubViewClickEvents();
    }



    @Override
    public void initData() {
        super.initData();

    }

    @Override
    protected void onStart() {
        super.onStart();
//        Log.d("onStart:","ssssssssss");
    }

    @Override
    protected void onResume() {
        super.onResume();
//        Log.d("onStart:","ssss22222ssssss");
        loadUserData();
    }

    private void bindSubViewClickEvents() {
        walletTitleBar.setOnTitleBarListener(new OnTitleBarListener() {
            @Override
            public void onLeftClick(View v) {
                finish();
            }

            @Override
            public void onTitleClick(View v) {

            }

            @Override
            public void onRightClick(View v) {

            }
        });
        walletRechargeB.setOnClickListener(this);
        walletWithdrawB.setOnClickListener(this);
        walletRechargeV.setOnClickListener(this);
        walletWithdrawV.setOnClickListener(this);
        walletChangeV.setOnClickListener(this);
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.wallet_recharge_btn:
                Intent recharge = new Intent(MineWalletActivity.this, MineWalletMoneyActivity.class);
                recharge.putExtra("title","recharge");
                startActivityForResult(recharge,REQUEST_CODE);
                break;
            case R.id.wallet_withdraw_btn:
                Intent intent = new Intent(MineWalletActivity.this, MineWalletMoneyActivity.class);
                intent.putExtra("title","withdraw");
                startActivityForResult(intent,REQUEST_CODE1);
                break;
            case R.id.wallet_recharge_record:
                Intent recharge_record = new Intent(MineWalletActivity.this, MineMoneyHistoryListActivity.class);
                recharge_record.putExtra("title","recharge");
                startActivity(recharge_record);
                break;
            case R.id.wallet_withdraw_record:
                Intent withdraw_record = new Intent(MineWalletActivity.this, MineMoneyHistoryListActivity.class);
                withdraw_record.putExtra("title","withdraw");
                startActivity(withdraw_record);
                break;
            case R.id.wallet_change_record:
                Intent change_record = new Intent(MineWalletActivity.this, MineMoneyHistoryListActivity.class);
                change_record.putExtra("title","moneychange");
                startActivity(change_record);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == REQUEST_CODE && resultCode == 1807) {
            Log.d("反向传值","success");
        }
    }


    private void loadUserData() {

        EasyHttp.get(Constants.KoiUserInfo)
                .params("id", SPUtils.getUserID(MineWalletActivity.this))//
                .execute(new CallBackProxy<CustomApiResult<KoiSeekModel>, KoiSeekModel>(new SimpleCallBack<KoiSeekModel>() {
                    @Override
                    public void onError(ApiException e) {
//                        ToastUtils.show("添加失败");

                    }

                    @Override
                    public void onSuccess(KoiSeekModel koiSeekModel) {


                        walletMoneyTV.setText(koiSeekModel.getMoney());
//                        TextView mobile = headView.findViewById(R.id.dcc_head_mobile);
//                        mobile.setText(koiSeekModel.getMobile());
//                        TextView level = headView.findViewById(R.id.dcc_head_level);
//                        level.setText(koiSeekModel.getQualification());//资格数
//                        TextView fans = headView.findViewById(R.id.dcc_head_fans);
//                        fans.setText(koiSeekModel.getR_code());
//
//                        TextView paypoint = headView.findViewById(R.id.dcc_head_paypoint);
//                        paypoint.setText(koiSeekModel.getShop_amount());
//
//                        TextView dcc = headView.findViewById(R.id.dcc_head_dccnum);
//                        if (koiSeekModel.getDcc() == null || koiSeekModel.getDcc().equals("") || koiSeekModel.getDcc().equals("null")) {
//                            dcc.setText("0");
//                        }else {
//                            dcc.setText(koiSeekModel.getDcc());
//                        }
//
//
//                        TextView kzpoint = headView.findViewById(R.id.dcc_head_kzpoint);
//                        kzpoint.setText(koiSeekModel.getSend_amount());
//                        TextView kypoint = headView.findViewById(R.id.dcc_head_kypoint);
//                        kypoint.setText(koiSeekModel.getUsable_amount());


//                        ToastUtils.show("添加成功");

                    }
                }) {
                });
    }
}
